﻿using ColemanSoftware.Delicious.Modules.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ColemanSoftware.Delicious.Modules.DeliciousFactory
{
    public class TagFactory
    {
        public enum TagFilterType
        {
            SEMICOLON,
            COMMA,
            PIPE
        }

        public static List<Tag> CreateTagFromString(string stringTags, TagFilterType filterType = TagFilterType.COMMA)
        {
            List<Tag> returnData = new List<Tag>();
            string stringFilter = ConvertTagFilterToStringFilter(filterType);
            returnData = ConvertStringArrayToTags(stringTags, stringFilter);

            return returnData;
        }

        private static string ConvertTagFilterToStringFilter(TagFilterType filterType)
        {
            string stringFilterConverted = "";

            switch (filterType)
            {
                case TagFilterType.SEMICOLON:
                    {
                        stringFilterConverted = ";";
                        break;
                    }
                case TagFilterType.COMMA:
                    {
                        stringFilterConverted = ",";
                        break;
                    }
                case TagFilterType.PIPE:
                    {
                        stringFilterConverted = "|";
                        break;
                    }
                default:
                    {
                        stringFilterConverted = ",";
                        break;
                    }
            }
            return stringFilterConverted;
        }

        public static List<Tag> ConvertStringArrayToTags(string tags, string filter)
        {
            List<Tag> tagList = new List<Tag>();
            string[] stringTags = tags.Split(Convert.ToChar(filter));

            if (stringTags != null && stringTags.Any())
                tagList = stringTags.Select(item => new Tag() { Name = item, Value = item }).ToList();

            return tagList;
        }

    }
}
